package com.dkd.easybook.controller;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.core.page.TableDataInfo;
import com.dkd.common.enums.BusinessType;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.easybook.domain.EbAccount;
import com.dkd.easybook.service.IEbAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * 记账列表Controller
 *
 * @author itheima
 * @date 2024-12-13
 */
@Api(tags = "记账列表Controller")
@RestController
@RequestMapping("/easybook/accountList")
public class EbAccountController extends BaseController {
    @Autowired
    private IEbAccountService ebAccountService;
    /**
     * 查询记账列表列表
     */
    @ApiOperation("查询记账列表列表")
    @PreAuthorize("@ss.hasPermi('easybook:accountList:list')")
    @GetMapping("/list")
    public TableDataInfo list(EbAccount ebAccount) {
        startPage();
        List<EbAccount> list = ebAccountService.selectEbAccountList(ebAccount);
        return getDataTable(list);
    }
    /**
     * 导出记账列表列表
     */
    @ApiOperation("导出记账列表列表")
    @PreAuthorize("@ss.hasPermi('easybook:accountList:export')")
    @Log(title = "记账列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EbAccount ebAccount) {
        List<EbAccount> list = ebAccountService.selectEbAccountList(ebAccount);
        ExcelUtil<EbAccount> util = new ExcelUtil<EbAccount>(EbAccount.class);
        util.exportExcel(response, list, "记账列表数据");
    }
    /**
     * 获取记账列表详细信息
     */
    @ApiOperation("获取记账列表详细信息")
    @PreAuthorize("@ss.hasPermi('easybook:accountList:query')")
    @GetMapping(value = "/{accountId}")
    public AjaxResult getInfo(@PathVariable("accountId") Long accountId) {
        return success(ebAccountService.selectEbAccountByAccountId(accountId));
    }
    /**
     * 新增记账列表
     */
    @ApiOperation("新增记账列表")
    @PreAuthorize("@ss.hasPermi('easybook:accountList:add')")
    @Log(title = "记账列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EbAccount ebAccount) {
        return toAjax(ebAccountService.insertEbAccount(ebAccount));
    }
    /**
     * 修改记账列表
     */
    @ApiOperation("修改记账列表")
    @PreAuthorize("@ss.hasPermi('easybook:accountList:edit')")
    @Log(title = "记账列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EbAccount ebAccount) {
        Integer result = ebAccountService.updateEbAccount(ebAccount);
        return toAjax(result);
    }
    /**
     * 删除记账列表
     */
    @ApiOperation("删除改记账列表")
    @PreAuthorize("@ss.hasPermi('easybook:accountList:remove')")
    @Log(title = "记账列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{accountIds}")
    public AjaxResult remove(@PathVariable Long[] accountIds) {
        return toAjax(ebAccountService.deleteEbAccountByAccountIds(accountIds));
    }
}
